<HTML><HEAD><TITLE>integer(+Number, -Result)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Arithmetic</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>integer(+Number, -Result)</H1>
Convert an integral number of any type to an integer
<DL>
<DT><EM>Number</EM></DT>
<DD>A number.
</DD>
<DT><EM>Result</EM></DT>
<DD>A variable or integer.
</DD>
</DL>
<H2>Description</H2>
   This predicate is used by the ECLiPSe compiler to expand evaluable
   arithmetic expressions.  So the call to integer(Number, Result) is
   equivalent to
<PRE>
    Result is integer(Number)
</PRE>
    which should be preferred for portability.
<P>
    This is a pure type conversion operation. If Number has an integral value
    of any type, Result is that same value, but represented as an integer.
    If Number does not have an integral value, an exception is raised.
    This function should therefore normally be applied to the result of
    one of the rounding operations floor, ceiling, round or truncate.
<P>
   In coroutining mode, if Number is uninstantiated, the call to integer/2 is
   delayed until this variable is instantiated.
<P>

<H3>Modes and Determinism</H3><UL>
<LI>integer(+, -) is det
</UL>
<H3>Exceptions</H3>
<DL>
<DT><EM>(4) instantiation fault </EM>
<DD>Number is not instantiated (non-coroutining mode only).
<DT><EM>(5) type error </EM>
<DD>Number is of type breal.
<DT><EM>(20) arithmetic exception </EM>
<DD>Number is not integral.
<DT><EM>(24) number expected </EM>
<DD>Number is not of a numeric type.
</DL>
<H2>Examples</H2>
<PRE>
Success:
      X is integer(5.0).               (gives X = 5)

      integer(5, 5).
      integer(5.0, 5).
      integer(5_1, 5).
      integer(5.0__5.0, 5).

Fail:
      integer(0.0, 0.0).
      integer(1, r).

Error:
      integer(1.1, X).                 (Error 20)
      integer(5_4, X).                 (Error 20)
      integer(0.99__1.01, X).          (Error 20)
      integer(A, 6.0).                 (Error 4).
      integer(4 + 2.3, 6).             (Error 24).
</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/arithmetic/is-2.html">is / 2</A>, <A HREF="../../kernel/arithmetic/floor-2.html">floor / 2</A>, <A HREF="../../kernel/arithmetic/ceiling-2.html">ceiling / 2</A>, <A HREF="../../kernel/arithmetic/round-2.html">round / 2</A>, <A HREF="../../kernel/arithmetic/truncate-2.html">truncate / 2</A>
</BODY></HTML>
